package com.tengfei.experiment2_3;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.tengfei.experiment2_3.adapter.MyRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity {
    private List<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);

        initData();
        RecyclerView rvDemo = findViewById(R.id.rv_demo);
        // LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        // layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        // GridLayoutManager layoutManager = new GridLayoutManager(this, 4);
        // layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,
                StaggeredGridLayoutManager.HORIZONTAL);

        rvDemo.setLayoutManager(layoutManager);

        rvDemo.setAdapter(new MyRecyclerViewAdapter(this, data));
    }

    private void initData() {
        data = new ArrayList<String>();
        for (int i = 'A'; i <= 'Z'; i++) {
            data.add("" + (char) i);
        }
    }
}